<template>
  <div class="wrapper">
    <el-form :inline="true">
      <el-form-item>
        <el-dropdown @command="setType">
          <span class="el-dropdown-link">
            {{typeStr}}
            <i class="el-icon-arrow-down el-icon--right"></i>
          </span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item :command="{value: '', title: '全部类型' }">全部类型</el-dropdown-item>
            <el-dropdown-item :command="{value: '1', title: '部门' }">部门</el-dropdown-item>
            <el-dropdown-item :command="{value: '2', title: '个人' }">个人</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </el-form-item>
      <el-form-item>
        <el-dropdown @command="setNum">
          <span class="el-dropdown-link">
            {{numStr}}
            <i class="el-icon-arrow-down el-icon--right"></i>
          </span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item :command="{value: '', title: '全部拉新目标状态' }">全部拉新目标状态</el-dropdown-item>
            <el-dropdown-item :command="{value: '1', title: '完成' }">完成</el-dropdown-item>
            <el-dropdown-item :command="{value: '2', title: '未完成' }">未完成</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </el-form-item>
      <el-form-item>
        <el-dropdown @command="setOrder">
          <span class="el-dropdown-link">
            {{orderStr}}
            <i class="el-icon-arrow-down el-icon--right"></i>
          </span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item :command="{value: '', title: '全部订单额目标状态' }">全部订单额目标状态</el-dropdown-item>
            <el-dropdown-item :command="{value: '1', title: '完成' }">完成</el-dropdown-item>
            <el-dropdown-item :command="{value: '2', title: '未完成' }">未完成</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </el-form-item>
      <el-form-item>
        <el-select v-model="dept"
          placeholder="请选择部门"
          @change="_reset">
          <el-option value=""
            label="全部部门"></el-option>
          <el-option v-for="item in depts"
            :key="item.id"
            :value="item.id"
            :label="item.name"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-date-picker v-model="startEndTime"
          @change="daterangeChange"
          size="small"
          style="height:34px;width:230px"
          type="daterange"
          range-separator="至"
          value-format="yyyy-MM-dd"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-input placeholder="请输入绩效目标名称"
          v-model="name"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary"
          size="small"
          style="width:60px"
          @click="_reset">
          <i class="el-icon-search"></i>
        </el-button>
      </el-form-item>
    </el-form>
    <el-form>
      <el-form-item>
        <el-table :data="overviewList">
          <el-table-column fixed
            label="编号"
            prop="id">
          </el-table-column>
          <el-table-column label="绩效目标名称"
            prop="name">
          </el-table-column>
          <el-table-column label="部门"
            prop="dept">
          </el-table-column>
          <el-table-column label="拉新目标"
            prop="newNum">
          </el-table-column>
          <el-table-column label="已拉新量"
            prop="yetPull">
          </el-table-column>
          <el-table-column label="拉新完成比"
            prop="newCase">
          </el-table-column>
         
          <el-table-column label="订单目标"
            prop="order">
          </el-table-column>
           <el-table-column label="已产生订单"
            prop="yetOrder">
          </el-table-column>
           <el-table-column label="订单完成比例"
            prop="orderCase">
          </el-table-column>
          <el-table-column label="当前奖励"
            prop="money">
          </el-table-column>
          <el-table-column label="绩效周期"
            width="200"
            prop="time">
          </el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button type="text"
                @click="_detail(scope.row.id)">查看目标总揽详情</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-form-item>
      <el-form-item class="fr">
        <el-pagination @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pageNum"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="pageSize"
          layout="total, prev , pager , next, sizes"
          :total="total"
          style="margin-top:20px">
        </el-pagination>
      </el-form-item>
    </el-form>
    <el-dialog title="绩效目标总揽详情"
      :visible.sync="dialogVisible"
      v-if="dialogVisible"
      width="1000px">
      <el-table :data="overviewDetailList"
        height="550px">
        <el-table-column fixed
          label="编号"
          prop="id">
        </el-table-column>
        <el-table-column label="绩效目标名称"
          prop="name">
        </el-table-column>
        <el-table-column label="部门"
          prop="dept">
        </el-table-column>
        <el-table-column label="类型"
          prop="type">
        </el-table-column>
        <el-table-column label="拉新量"
          prop="newNum">
        </el-table-column>
        <el-table-column label="拉新目标"
          prop="newCase">
        </el-table-column>
        <el-table-column label="订单目标"
          prop="order">
        </el-table-column>
        <el-table-column label="当前奖励"
          prop="money">
        </el-table-column>
        <el-table-column label="绩效周期"
          prop="time">
        </el-table-column>
      </el-table>
      <el-pagination @size-change="_handleSizeChange"
        @current-change="_handleCurrentChange"
        :current-page="_pageNum"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="_pageSize"
        layout="total, prev , pager , next, sizes"
        :total="_total"
        style="margin-top:20px">
      </el-pagination>
      <span slot="footer"
        class="dialog-footer">
        <el-button @click="dialogVisible = false">关 闭</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {
  getPullDeptList,
  overviewList,
  overvieInfo
} from "@/public/js/performance";
export default {
  components: {},
  props: {},
  data() {
    return {
      startEndTime: "全部",
      typeStr: "全部类型",
      numStr: "全部拉新目标状态",
      orderStr: "全部订单额目标状态",
      dialogVisible: false,
      overviewList: [],
      overviewDetailList: [],
      month: [],
      dept: "",
      depts: [],
      pageNum: 1,
      pageSize: 10,
      _pageNum: 1,
      _pageSize: 10,
      _total: 0,
      total: 0,
      name: "",
      dept: "",
      type: "",
      numType: "",
      orderType: "",
      startEndTime: [],
      id: ""
    };
  },
  watch: {},
  computed: {},
  methods: {
    _reset() {
      this.pageNum = 1;
      this.pageSize = 10;
      this._overviewList();
    },
    // 获取列表数据
    _overviewList() {
      overviewList({
        pageSize: this.pageSize,
        pageNum: this.pageNum,
        name: this.name,
        dept: this.dept,
        type: this.type,
        numType: this.numType,
        orderType: this.orderType,
        startTime: this.startEndTime ? this.startEndTime[0] : "",
        endTime: this.startEndTime ? this.startEndTime[1] : ""
      }).then(res => {
        this.total = res.data.total;
        this.overviewList = res.data.overviewList;
      });
    },
    _overvieInfo() {
      overvieInfo({
        id: this.id,
        pageSize: this._pageSize,
        pageNum: this._pageNum
      }).then(res => {
        console.log(res);
        this.overviewDetailList = res.data.overviewList;
        this._total = res.data.total;
        this.dialogVisible = true;
      });
    },
    //查看详情
    _detail(id) {
      this.id = id;
      this._pageNum = 1;
      this._pageSize = 10;
      this._total = 0;
      this._overvieInfo();
    },
    // 获取部门下拉数据
    _getPullDeptList() {
      getPullDeptList({
        id: ""
      }).then(res => {
        this.depts = res.data.depts;
      });
    },
    // 设置类型
    setType(type) {
      this.type = type.value;
      this.typeStr = type.title;
      this._reset();
    },
    // 设置拉新状态
    setNum(numType) {
      this.numType = numType.value;
      this.numStr = numType.title;
      this._reset();
    },
    // 设置订单目标状态
    setOrder(orderType) {
      this.orderType = orderType.value;
      this.orderStr = orderType.title;
      this._reset();
    },
    // 绩效周期选择
    daterangeChange() {
      this._reset();
    },
    //分页
    handleSizeChange(pageSize) {
      this.pageSize = pageSize;
      this._overviewList();
    },
    handleCurrentChange(pageNum) {
      this.pageNum = pageNum;
      this._overviewList();
    },
    //详情列表分页
    _handleSizeChange(pageSize) {
      this._pageSize = pageSize;
      this._overvieInfo();
    },
    _handleCurrentChange(pageNum) {
      this._pageNum = pageNum;
      this._overvieInfo();
    }
  },
  created() {
    this._getPullDeptList();
    this._overviewList();
  },
  mounted() {}
};
</script>
<style lang="scss" scoped>
.wrapper {
  .el-input {
    width: 200px;
  }
}
</style>